package TDALista;
import java.util.Iterator;

public class ElementIterator<E> implements Iterator<E> {
	
	private PositionList<E> lista;
	private Position<E> cursor;
	
	public ElementIterator(PositionList<E> l){
		lista = l;
		try{
			cursor = (lista.isEmpty()) ? null : lista.first();
		}
		catch(EmptyListException e){
			System.out.println(e.getMessage());
		}
	}
	
	public boolean hasNext(){
		return cursor != null;
	}
	
	public E next() {
		if (cursor == null){}
			//throw new NoSuchElementException("No hay siguiente");
		E tmp = cursor.element();
		try{
			cursor = (cursor == lista.last()) ? null : lista.next(cursor);
		
		}
		catch(EmptyListException | BoundaryViolationException | InvalidPositionException e){
			System.out.println(e.getMessage());
		}
		return tmp;		
	}

	@Override
	public void remove() {
		// TODO Auto-generated method stub
		
	}
}
